package hos.java.util;

/**
 * <p>Title: CharSequenceUtils </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2023/3/7 22:52
 */
public class CharSequenceUtils {
    public CharSequenceUtils() {
    }

    public static CharSequence subSequence(CharSequence cs, int start) {
        return cs == null ? null : cs.subSequence(start, cs.length());
    }

    static int indexOf(CharSequence cs, int searchChar, int start) {
        if (cs instanceof String) {
            return ((String) cs).indexOf(searchChar, start);
        } else {
            int sz = cs.length();
            if (start < 0) {
                start = 0;
            }

            if (searchChar < 65536) {
                for (int i = start; i < sz; ++i) {
                    if (cs.charAt(i) == searchChar) {
                        return i;
                    }
                }

                return -1;
            } else {
                if (searchChar <= 1114111) {
                    char[] chars = Character.toChars(searchChar);

                    for (int i = start; i < sz - 1; ++i) {
                        char high = cs.charAt(i);
                        char low = cs.charAt(i + 1);
                        if (high == chars[0] && low == chars[1]) {
                            return i;
                        }
                    }
                }

                return -1;
            }
        }
    }
}
